import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/controllers/device/call_remind/call_const.dart';
import 'package:share_fit/app/controllers/device/call_remind/call_remind_logic.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/generated/locales.g.dart';

class CallRingingPage extends StatelessWidget {
  final logic = Get.put(CallRemindLogic());
  final state = Get.find<CallRemindLogic>().state;

  CallRingingPage({super.key});

  @override
  Widget build(BuildContext context) {
    state.callRingRing =
        logic.read(CallConst.keyCallRingRing, defaultValue: false);
    state.callRingVibrate =
        logic.read(CallConst.keyCallRingVibrate, defaultValue: false);
    state.callRingRingVibrate =
        logic.read(CallConst.keyCallRingRingVibrate, defaultValue: false);
    state.callRingMute =
        logic.read(CallConst.keyCallRingMute, defaultValue: false);
    return Scaffold(
      appBar: AppBar(
        title: Text(
          LocaleKeys.call_ringing.ts,
          style: TextStyle(fontSize: 54.sp, color: ColorConst.btnFontColor),
        ),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back()),
      ),
      body: ListView(
        padding: EdgeInsets.fromLTRB(42.w, 100.w, 42.w, 0),
        children: [
          _buildItem(LocaleKeys.call_ringing_ring.ts, CallConst.keyCallRingRing,
              onChange: (value) {
            logic.setCallRing(CallConst.keyCallRingRing, value);
          }),
          _buildItem(
              LocaleKeys.call_ringing_vibrate.ts, CallConst.keyCallRingVibrate,
              onChange: (value) {
            logic.setCallRing(CallConst.keyCallRingVibrate, value);
          }),
          _buildItem(LocaleKeys.call_ringing_ring_vibrate.ts,
              CallConst.keyCallRingRingVibrate, onChange: (value) {
            logic.setCallRing(CallConst.keyCallRingRingVibrate, value);
          }),
          _buildItem(LocaleKeys.call_ringing_mute.ts, CallConst.keyCallRingMute,
              onChange: (value) {
            logic.setCallRing(CallConst.keyCallRingMute, value);
          }),
        ],
      ),
    );
  }

  Widget _buildItem(String title, String id, {onChange}) {
    Widget widget = Container(
      margin: EdgeInsets.only(bottom: 40.h),
      padding: EdgeInsets.fromLTRB(60.w, 20.h, 36.w, 20.h),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10), color: Colors.white),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            title,
            style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor),
          ),
          Transform.scale(
            scale: 0.7,
            child: GetBuilder<CallRemindLogic>(
              id: id,
              builder: (value) {
                return CupertinoSwitch(
                    value: logic.switchCallRing(id),
                    activeColor: ColorConst.accentColor,
                    onChanged: onChange);
              },
            ),
          ),
        ],
      ),
    );
    return widget;
  }

}
